package com.yuandian.management.socket.entity;


import cn.hutool.core.util.RandomUtil;
import com.yuandian.management.utils.SHAUtils;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * 请求报文头部对象
 *
 * @author: tangqingchun
 * @date: 2019-09-27
 */
public class SocketRequestHead {
    /**
     * 固定值，请求消息为request,响应消息为response
     */
    private String messageType;
    /**
     * 消息ID，格式为：yyyymmddhhMMssSSS+3位随机数
     */
    private String messageId;
    /**
     * 时间戳
     */
    private Long timeStamp;
    /**
     * 鉴权信息，取值为：
     * SHA(当前日期yyyymmdd格式+KEY+PASSWORD)
     * 其中KEY=appId+moduleId+operType
     * PASSWORD=自定义的密码，交互双方相同
     */
    private String authInfo;
    /**
     * 系统标识，具体请参看附录：应用标识枚举
     */
    private String appId;
    /**
     * 模块标识，具体请参看附录：模块标识枚举
     */
    private String moduleId;
    /**
     * 操作类型，具体请参看附录：操作类型枚举
     */
    private Integer operType;
    
	/**
	 * 初始化SocketRequestHead
	 * @param appId
	 * @param moduleId
	 * @param operType
	 */
	public SocketRequestHead(String appId, String moduleId, Integer operType) {
		super();
		this.appId = appId;
		this.moduleId = moduleId;
		this.operType = operType;
		String nowDateStr = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd"));
		this.authInfo = SHAUtils.encrypt(nowDateStr + appId + moduleId + operType);
		this.timeStamp = System.currentTimeMillis();
		String messageDate = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmssSSS"));
		this.messageId = messageDate + RandomUtil.randomNumbers(3) ;
		this.messageType = "request";
	}


	/**
	 * @return the messageType
	 */
	public String getMessageType() {
		return messageType;
	}

	/**
	 * @return the messageId
	 */
	public String getMessageId() {
		return messageId;
	}

	/**
	 * @return the timeStamp
	 */
	public Long getTimeStamp() {
		return timeStamp;
	}

	/**
	 * @return the authInfo
	 */
	public String getAuthInfo() {
		return authInfo;
	}

	/**
	 * @return the appId
	 */
	public String getAppId() {
		return appId;
	}

	/**
	 * @return the moduleId
	 */
	public String getModuleId() {
		return moduleId;
	}

	/**
	 * @return the operType
	 */
	public Integer getOperType() {
		return operType;
	}
	
}
